package com.feicheng.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.feicheng.base.common.DaoConstant;
import com.feicheng.base.result.Result;
import com.feicheng.entity.User;
import com.feicheng.service.ProviderUserController;
import com.feicheng.service.ProviderWarehouseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yvming.gao
 * @since 2022-07-4
 */
@RestController
@RequestMapping("/user")
public class UserController {

    /*注入业务逻辑对象*/
    @Autowired
    ProviderUserController providerProcurementController;
    @Autowired
    ProviderWarehouseController providerWarehouseController;

    /*注入session对象*/
    @Autowired
    HttpSession session;

    /**
     * @param user 业务参数 （查询条件）
     * @author yvming.gao
     * @return
     */
    @GetMapping("/info/g")
    public Result getUserInfo(User user) {

        /*接收返回值*/
        Result result = providerProcurementController.getUserInfo(user);

        /*判断登录返回值*/
        if (result.get(DaoConstant.USER.RESULT_DATA).toString().length() > 0){

            /*把信息注入到session中*/
            session.setAttribute(DaoConstant.USER.USERINFO,result);

            /*返回登录验证成功结果*/
            return Result.success(result);
        }
        /*返回登录验证失败结果*/
        return Result.success(false);
    }
    /**
     * 管理员下拉查询
     * @autor hao.zhang
     * @param
     * @return
     */
    @GetMapping("/info/all")
    public Result getUserList(Integer storeId) {
        return Result.success(providerWarehouseController.getUserList(storeId));
    }
}
